package cn.iocoder.yudao.module.crossborder.logistics.api;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.crossborder.logistics.api.dto.LogisticsDTO;
import cn.iocoder.yudao.module.crossborder.logistics.api.dto.TrackingDTO;
import cn.iocoder.yudao.module.crossborder.logistics.service.LogisticsService;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * 物流管理 API 接口实现类
 *
 * @author LHL
 */
@RestController // 提供 RESTful API 接口，给 Feign 调用
@Validated
public class LogisticsApiImpl implements LogisticsApi {

    @Resource
    private LogisticsService logisticsService;

    @Override
    public CommonResult<LogisticsDTO> getLogistics(Long id) {
        LogisticsDTO logistics = logisticsService.getLogistics(id);
        return success(logistics);
    }

    @Override
    public CommonResult<List<LogisticsDTO>> getLogisticsList(List<Long> ids) {
        List<LogisticsDTO> logisticsList = logisticsService.getLogisticsList(ids);
        return success(logisticsList);
    }

    @Override
    public CommonResult<Long> createLogistics(LogisticsDTO logistics) {
        Long id = logisticsService.createLogistics(logistics);
        return success(id);
    }

    @Override
    public CommonResult<TrackingDTO> getTracking(String trackingNumber) {
        TrackingDTO tracking = logisticsService.getTracking(trackingNumber);
        return success(tracking);
    }

    @Override
    public CommonResult<BigDecimal> calculateFreight(Long orderId, BigDecimal weight, String destination) {
        BigDecimal freight = logisticsService.calculateFreight(orderId, weight, destination);
        return success(freight);
    }

    @Override
    public CommonResult<Boolean> ship(Long orderId, Long providerId) {
        Boolean result = logisticsService.ship(orderId, providerId);
        return success(result);
    }

    @Override
    public CommonResult<Boolean> updateStatus(Long logisticsId, Integer status) {
        Boolean result = logisticsService.updateStatus(logisticsId, status);
        return success(result);
    }

}
